package com.quanyan.club.util;

import com.quanyan.common.utils.PinYinUtils;
import com.quanyan.common.utils.StringUtil;
import org.apache.commons.lang.StringUtils;

/**
 * Created by zhuo.shi on 2016/11/18.
 */
public class ClubNameUtils {

    public static String getClubNamePinYin(String clubName){
        if (StringUtil.isBlankOrNull(clubName)){
            return "";
        }
        clubName = clubName.toLowerCase();
        StringBuilder py = new StringBuilder();
        for (char n : clubName.toCharArray()){
            if (PinYinUtils.isChinese(String.valueOf(n))){
                py.append(PinYinUtils.hanyuToPinyin(String.valueOf(n)));
            }else {
                py.append(n);
            }
        }
        String name = py.toString().replaceAll(":", "");
        return name;
    }

    public static boolean clubNameContainsEN(String clubName){
        if (StringUtil.isBlankOrNull(clubName)){
            return false;
        }

        if(clubName.matches(".*[0-9a-zA-Z]+.*")) {
            return true;
        }
        return false;
    }

    public static boolean clubNameContainsCN(String clubName){
        if (StringUtil.isBlankOrNull(clubName)){
            return false;
        }
        for (char n : clubName.toCharArray()){
            if (PinYinUtils.isChinese(String.valueOf(n))){
                return true;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        String clubName = "54";
        //System.out.println(ClubNameUtils.getClubNamePinYin(clubName));
        System.out.println(ClubNameUtils.clubNameContainsCN(clubName));
        System.out.println(ClubNameUtils.clubNameContainsEN(clubName));

        System.out.println("kaolu:kaolu:".replaceAll(":", ""));
    }
}
